﻿using System.Collections.Generic;
using System.Linq;
using WYJCore;
using WYJData.DatabaseAccess;

namespace WYJWeb
{
    public abstract class BaseModel : IModel
    {
        [Column(IsPK = true,Identity = true)]
        public int Id { get; set; }


        public static string Muid(char Char)
        {
            //68B84974-F6DA-49BA-9A43-2ED66844B969
            char[] cs = new char[36]
            {
                Char,Char,Char,Char,Char,Char,Char,Char,'-',
                Char,Char,Char,Char,'-',
                Char,Char,Char,Char,'-',
                Char,Char,Char,Char,'-',
                Char,Char,Char,Char,Char,Char,Char,Char,Char,Char,Char,Char
            };
            return new string(cs);
        }

        public virtual bool IsNull()
        {
            return Id == 0;
        }
    }

    public abstract class GetAllable<T> : BaseModel where T : class, IModel
    {
        public static Dictionary<int, T> GetAll()
        {
            var db = new Database();
            return db.GetList<T>().ToDictionary(x => x.Id);
        }
    }
}
